This is the replication package for:

Stephen A. Meserve, Daniel Pemstein, and William T. Bernhard.
"Gender, Incumbency, and Party List Nomination."
British Journal of Political Science.

This package includes the following files:

data/                               - Raw data directory.
data/candidates.dta                 - Raw candidate-level data.
data/Combinedcountrylevelgender.csv - Country-level labor force, quota.
data/EECS 2009 Full Release V1.dta  - MEP candidate survey.
data/electionrules.csv              - Election rules (district mag).
data/party-leaders.csv              - Raw data on women party leaders.
data/parties.dta                    - Raw party-level data.
doc/                                - Documentation directory.
doc/codebook.txt                    - Codebook describing raw data.
doc/codebook.txt                    - Contains explanations of variables
                                      in the data files.
doc/EECS2009.pdf                    - Codebook for the PIREDEU 2009
                                      European Candidate Study.
doc/EEMS2009.pdf                    - Codebook for the PIREDEU 2009
                                      European Manifesto Study.
doc/EESC2009.pdf                    - Codebook for the PIREDEU 2009 EES
                                      Contextual Data.
fig-funcs.R                         - Functions for creating figures.
fit-incnat.R                        - Fit appendix figure 7 model.
fit-main.R                          - Fit main text model.
fit-natwom.R                        - Fit appendix figure 6 model.
fit-noireland.R                     - Fit appendix figure 4 model.
fit-openlist.R                      - Fit appendix figure 5 model.
gender-groups-incnat.R              - DV construction app fig 7 model.
gender-groups-inc.R                 - DV construction all other models.
nomep_0.1.tar.gz                    - A source-based R package for fitting
                                      the ranking model described in
                                      the manuscript. This is a
                                      bare-bones piece of software and
                                      is not documented. Please
                                      contact the authors if you need
                                      help installing or using the
                                      package.
posts/                              - A directory for holding fitted
                                      models.
posts/*                             - Pre-fit models (using fit-*)
predacc.R                           - Script computes model accuracy.
prep1.R                             - A prep sub-script.
prep2.R                             - A prep sub-script.
prep-incnat.R                       - Prep data for app fig 7 model.
prep-main.R                         - Prep data for main model, app
                                      fig 6 model.
prep-noireland.R                    - Prep data for app fig 4-5 models.
preps/                              - A directory for holding
                                      prepped/merged data files.
preps/prep.RData                    - Pre-merged data for the primary
                                      analysis.
preps/prep-incnat.RData             - Pre-merged data for app fig 7 model.
preps/prep-noireland.RData          - Pre-merged data for app figs
                                      4-5 model.
preps/prep.RData                    - Pre-merged data for main model,
                                      app fig 6 model.
README.txt                          - This file.
results-appendix.R                  - Generate results in appendix.
results-main.R                      - Generate results in the main
                                      text and fig 8 in appendix.

To replicate the analysis (note that file system paths in scripts
follow unix conventions, you may need to switch the slashes from
forward to back on windows machines):

1. Install the nomep R library included in this replication package.
The authors have tested this library on our own Linux, OS X and
Windows machines, but we cannot guarantee that it will work on your
platform.  While we are happy to field questions about using this
software (contact Dan Pemstein at daniel.pemstein@ndsu.edu), please
consult the extensive R documentation on installing packages and/or
your local sysadmin before asking the authors for help with installing
the package on your system.  We simply cannot replicate every possible
install target, nor are we able to devote substantial time to
diagnosing the peculiarities of your system.  This is not production
quality software and we cannot formally support it; use at your own
risk.

2. Once nomep is installed, start up an R session and set your working
directory to the src folder in this package (replace PATHTOPACKAGE as
appropriate on your system).  All the steps below assume you are
running an R session in this working directory.

> setwd("PATHTOPACKAGE/src")

3. Merge data for the primary analysis (this overwrites preps/prep.RData):

> source("prep-main.R")

4. Fit the main model presented in the results section of the paper:

> rm(list=ls())
> source("fit-main.R")

Note that this will take quite some time (probably upwards of 24
hours, even on a very fast 4+ core machine by 2015 standards).
You can shorten the sample run time by setting the MCMC and BURNIN
variables in src/main-model.R (adjust THIN appropriately to get the
number of sample draws that you want), although chains may not
converge sufficiently if you reduce the number of samples drawn.  We
have had trouble running the model fitting code from within RStudio.
Rather, one should use a vanilla R session.

Note that while we set fixed RNG seeds for the MCMC sampler we
neglected to set a seed for the beta starting values that are drawn in
R and passed to the C++ code, and did not store the starting values we
used when fitting the model for the paper, thus any given run of the
model will produce slightly different values from what we report in
the paper.  These differences should be negligible, but,
unfortunately, preclude perfect reproduction of the manuscript
results.

5. Conduct the core analysis presented in the paper's results section.
This generates the figures 1-6 and quoted stats in the main text. It
also generates figures 1-3, and 8, and quoted stats for figure 8, in 
the appendix.

> rm(list=ls())
> source("results-main.R", echo=T)

6. Do predictive accuracy analysis in footnote 31.

> rm(list=ls())
> source("predacc.R", echo=T)

7. Fit robustness models in appendix:

> rm(list=ls())
> source("prep-noireland.R")
> rm(list=ls())
> source("fit-noireland.R")
> rm(list=ls())
> source("fit-openlist.R")
> rm(list=ls())
> source("prep-incnat.R")
> rm(list=ls())
> source("fit-incnat.R")
> rm(list=ls())
> source("fit-natwom.R")

This will take quite a while.

8. Generate appendix figures 4-7:

> rm(list=ls())
> source("results-appendix.R")
